/**
 * 
 */
package sv.gob.mh.dgii.ssc.constants;

import java.util.Calendar;
import java.util.Date;

/**
 * @author jose.escobar
 *
 */
public class DateUtilsCommons {

	 
	/**
	 * @param date
	 * @return Devuelve un Calendario a partir de una fecha
	 */
	public static Calendar getCalendarFromDate(Date date){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal;
	}
	
	/**
	 * @param before
	 * @param after
	 * @return Devuelve true si before es antes (o el mismo dia) que after
	 */
	public static boolean isBefore(Date before, Date after){
		Calendar calBefore = getCalendarFromDate(before);
		Calendar calAfter = getCalendarFromDate(after);
		return (calBefore.before(calAfter) || 
				(calBefore.get(Calendar.YEAR) == calAfter.get(Calendar.YEAR) &&
						calBefore.get(Calendar.MONTH) == calAfter.get(Calendar.MONTH) &&
						calBefore.get(Calendar.DAY_OF_MONTH) == calAfter.get(Calendar.DAY_OF_MONTH) ) );
	}
	
}
